package  com.soft.hwx.scdapp;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;



import java.util.ArrayList;
import java.util.List;

/*
 *Crated by yedona on 2018/9/17
 */
public class F1Fragment extends Fragment {
    private Spinner spinner;
    private List<String> data_list;
    private ArrayAdapter<String> arr_adapter;
    private int spinner_item_value = 0;
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        Log.d("homefragment", "onAttach");
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        Log.d("homefragment", "onCreate");
    }


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view= LayoutInflater.from(getContext()).inflate(R.layout.fragment_f1, null);
        Log.d("homefragment", "onCreateView");
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Log.d("homefragment", "onActivityCreated");
    }

    @Override
    public void onStart() {
        super.onStart();
        init_spinner();
        Log.d("homefragment", "onStart");

    }

    @Override
    public void onResume() {
        super.onResume();
        Log.d("homefragment", "onResume");
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.d("homefragment", "onPause");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.d("homefragment", "onCreateView");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.d("homefragment", "onDestroyView");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("homefragment", "onDestroy");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Log.d("homefragment", "onDetach");
    }


    public void init_spinner(){
        spinner = (Spinner)getView().findViewById(R.id.spinnerf1);
        //数据
        data_list = new ArrayList<String>();
        data_list.add(String.valueOf(1));
        data_list.add(String.valueOf(2));
        data_list.add(String.valueOf(3));

        // 适配器
        arr_adapter= new ArrayAdapter<String>(getActivity().getApplication(), R.layout.spinner_style, data_list);
        // 设置样式
        //arr_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // 加载适配器
        spinner.setAdapter(arr_adapter);


        spinner.setOnItemSelectedListener(new SpinnerSelectedListener());
    }


    class SpinnerSelectedListener implements AdapterView.OnItemSelectedListener {
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
                                   long arg3) {
            spinner_item_value = arg2;
            //Log.d("f1fragment", "下拉框："+String.valueOf((arg2)));
        }
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    }

    public int get_spinner_item(){ return spinner_item_value; }


}
